package servlet;

import bean.Comment;
import dao.entity.CommentDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "commentAddServlet", value = "/ccadd")
public class CommentAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取数据
        //String ccid = "cc1";
        String ccid = (String) request.getParameter("ccid");
        String cid = (String) request.getParameter("cid");
        String gid = (String) request.getParameter("gid");
        String cname = (String) request.getParameter("cname");
        String cc_time = (String) request.getParameter("cc_time");
        String content = (String) request.getParameter("content");
        //封装数据
        Comment c = new Comment(ccid,cid,gid,cname,cc_time,content);
        //执行插入操作
        //int n = SHelper.addS(student);
        CommentDaoImpl cdi = new CommentDaoImpl();
        int n = cdi.addComment(c);
        if(n!=0){
            //插入成功
            request.setAttribute("n",1);
        }else {
            //插入失败
            request.setAttribute("n",0);
        }
        request.getRequestDispatcher("result.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
